avatar

CTF-JarvisOJ-Crypto-[61dctf]bbencode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
flag = open("flag", "r").read().strip()
assert len(flag) == 32
def str2num(s):
return int(s.encode('hex'), 16)
def bbencode(n):
a = 0
for i in bin(n)[2:]:
a = a << 1
if (int(i)):
a = a ^ n
if a >> 256:
a = a ^ 0x10000000000000000000000000000000000000000000000000000000000000223L
return a
print bbencode(str2num(flag))
result:61406787709715709430385495960238216763226399960658358000016620560764164045692

由于异或本身是可逆运算,且分析算法可知每位异或的值还是一样的,所以直接用bbencode函数再异或一次,就可以逆回原码

python代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def bbencode(n):
a = 0
for i in bin(n)[2:]:
a = a << 1
if (int(i)):
a = a ^ n
if a >> 256:
a = a ^ 0x10000000000000000000000000000000000000000000000000000000000000223L
return a
result = 61406787709715709430385495960238216763226399960658358000016620560764164045692
for i in range(10000):
result = bbencode(result)
if("666c6167" == str(hex(result))[2:10]):
print i
print hex(result)[2:-1].decode('hex')
文章作者: 咲夜南梦
文章链接: http://yoursite.com/2018/12/11/CTF-JarvisOJ-Crypto-[61dctf]bbencode/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 咲夜南梦's 博客
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论